<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html><head>
    <meta charset="UTF-8">
    <title>首页_蜗牛图书商城</title>
    <link type="text/css" rel="stylesheet" href="css/index.css">
    <script src="js/jquery-3.4.1.js"></script>
</head>

<body class="index">
<div class="container">

   <header>
   </header>

    <div class="wrapper clearfix">
        <div class="sidebar f_r">
            <!--热卖商品-->
            <div class="hot box m_10">
                <div class="title">
                    <h2>热卖商品</h2>
                </div>
                <div class="cont clearfix">
                    <ul class="prolist" id="hot">
<!--                        <li>-->
<!--                            <a href="goodsDetail.html?gid=1">-->
<!--                            <img src="images/goods/ea9dd4c3107b445784d0771e695318e1.jpg" width="85" height="85" alt="企业IT架构转型之道 阿里巴巴中台战略思想与架构实战" title="企业IT架构转型之道 阿里巴巴中台战略思想与架构实战">-->
<!--                        </a>-->
<!--                            <p class="pro_title">-->
<!--                                <a href="goodsDetail.html?gid=1">企业IT架构转型之道 阿里巴巴中台战略思想与架构实战</a>-->
<!--                            </p>-->
<!--                            <p class="brown">	￥<b>99</b>	</p>-->
<!--                        </li>-->
                        </ul>
                </div>
            </div>
            <!--热卖商品-->
        </div>
        <div class="main f_l">
            <!--最新商品-->
            <div class="box yellow m_10">
                <div class="title title3">
                    <h2>
                        <img src="images/front/new_product.gif" alt="最新商品" width="160" height="36">
                    </h2>
                    <a class="more" href="goods.html?gtid=0">更多商品...</a>
                </div>
                <div class="cont clearfix">
                    <ul class="prolist" id="newest">
<!--                        <li style="overflow: hidden">-->
<!--                        <a href="goodsDetail.html?gid=272" target="_blank">-->
<!--                        <img src="images/goods/3adb08f37d7b47d5a62a2ad0a99ed355.jpg" width="175" height="175" alt="尘埃落定" title="尘埃落定">-->
<!--                        </a>-->
<!--                        <p class="pro_title">-->
<!--                        <a title="尘埃落定" href="goods?opr=view&amp;id=137">尘埃落定</a>-->
<!--                        </p>-->
<!--                        <p class="brown">	惊喜价：￥<b>38</b></p>-->
<!--                        <p class="light_gray">	市场价： ￥	<del>38</del></p>-->
                        </li>
                    </ul>
                </div>
            </div>

        </div>
    </div>
    <footer>
    </footer>
    </div>
    <script src="./js/jquery-1.12.4.min.js"></script>
    <script src="./js/include.js"></script>
<script>
    $(function() {
        $.ajax({
            url: "category.do",
            type: "get",
            data: {method: "list"},
            dataType: "json",
            success: function (result) {
                if (result.code == 200) {
                    $.each(result.data, function (index, item) {
                        //创建列表项<li><a href="#">首页</a></li>
                        if (item.navable == 'y') {
                            var $item = $("<li><a href=''>" + item.name + "</a></li>")
                            $("#goodsType").append($item);
                        }
                    });
                }
            }
        });
        var user=JSON.parse(window.sessionStorage.getItem("user"));
        if(user!=undefined){
        $.ajax({
            url:"Cart.do",
            data:{
                method:"findByCart",
                userid:user.id,
            },
            type:"get",
            dataType:"json",
            success:function(result) {
                $("#mycart_nums").text(parseInt(result.msg));
            }})
        }
        //请求最新图书
        $.ajax({
            url: "goods.do",
            type: "get",
            data: {
                method: "list",
                newest: "是",
            },
            dataType: "json",
            success: function (result) {
                for (let i = 0; i < result.data.length; i++) {
                    if(result.data[i].newest=="是"){
                    //	在goodsType。的子类后面继续添加（使用函数在被选元素的结尾插入内容。）
                    $("#newest").append("<li style=\"overflow: hidden\"><a href='goodsDetail.html?id=" + result.data[i].id + "' ><img src=" + result.data[i].image + " width=\"175\" height=\"175\" alt=\"" + result.data[i].name + " title=\"" + result.data[i].name + "\"></a><p class=\"pro_title\">\t<a title=\"" + result.data[i].name + "\" href=\"goods?opr=view&amp;id=137\">" + result.data[i].name + "</a></p><p class=\"brown\">\t惊喜价：￥<b>" + result.data[i].salesprice + "</b></p><p class=\"light_gray\">\t市场价： ￥\t<del>" + result.data[i].marketprice + "</del></p></li>>");
                }}
            }
        })
    //最火图书
    $.ajax({
        url: "goods.do",
        type: "get",
        data:{
            method:"list",
            hot:"是"
        },
        dataType:"json",
        success:function (result){

            for(let i=0;i<result.data.length;i++){
                console.log(result.data[i].id);
                if(result.data[i].hot=="是"){
                //	在goodsType。的子类后面继续添加（使用函数在被选元素的结尾插入内容。）
                    $("#hot").append("<li><a href='goodsDetail.html?id=" + result.data[i].id + "'><img src="+result.data[i].image+" width=\"85\" height=\"85\" alt=\""+result.data[i].name+" title=\""+result.data[i].name+"\"></a>\t<p class=\"pro_title\">\t<a href=\"goodsDetail.html?gid=1\">"+result.data[i].name+"</a>\t</p>\t<p class=\"brown\">\t￥<b>"+result.data[i].salesprice+"</b>\t</p></li>");
            }}
        }
    })
    });
</script>

</body></html>
